package dem1;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-07-17
 * Time: 15:10
 */
public class Test {

    public static void menu() throws SQLException {

        Scanner scanner = new Scanner(System.in);
        Work[] works = {new Add(), new Del(), new Mod(), new Search()};
        DataSource dataSource = new MysqlDataSource();

        System.out.println("*****************************");
        System.out.println("**** 1. Add    2. Del    ****");
        System.out.println("**** 3. Mod    4. Search ****");
        System.out.println("*******   0. exit  **********");

        while(scanner.hasNextInt()){
            int n = scanner.nextInt();
            switch (n){
                case 1:
                case 2:
                case 3:
                case 4:
                    works[n - 1].work(dataSource);
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
                    n = scanner.nextInt();
                    break;
            }
        }

    }

    public static void main(String[] args) throws SQLException {
        menu();
    }
}
